package com.ww.basic.fun

object curryingTest8 {
  def inject(arr: Array[Int], initial: Int)(opertion: (Int, Int) => Int): Int = {
    var carryOver = initial
    arr.foreach(element => carryOver = opertion(carryOver, element))
    carryOver
  }

  def main(args: Array[String]): Unit = {
    val array = Array(2, 2, 3, 5, 2, 1)
    val sum: Int = inject(array, 0) { (carryOver, elem) => carryOver + elem }
    println(sum)
  }
}
